package demo;

import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;

public class NewsDaoImpl implements NewsDao{
    private DataSource ds;
    public void setDs(DataSource ds)
    {
        this.ds = ds;
    }
    public void insert(String title, String content)
    {
        JdbcTemplate jt = new JdbcTemplate(this.ds);
        jt.update("insert into news_info "+ " values(1, ?, ?) ", title, content);
        //两次插入的数据 违反唯一键约束
        // jt.update("insert into news_info "+ " values(1, ?, ?) ", title, content);
        // 如果没有事务约束 则第一条会被插入
        // 如果有事务约束，则两条都不会被插入

    }
    
}
